package com.cdutetc.ssm.controller;

import com.cdutetc.ssm.pojo.Student;
import com.cdutetc.ssm.service.StudentService;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/student")
    public String getAllStudent(Model model){
        List<Student>list=studentService.getAllStudent();
        model.addAttribute("list",list);
        return "student_list";
    }
    @RequestMapping(value = "/student_add",method = RequestMethod.GET)
    public String addStudent(){
        return "student_add";
    }

    @RequestMapping(value = "/student_add",method = RequestMethod.POST)
    public String addStudent(Student student){
//        System.out.println(student);
        studentService.addStudent(student);

        return "redirect:/student";
    }
    @RequestMapping(value = "/student_delete/{studentId}",method = RequestMethod.GET)
    public String deleteStudent(@PathVariable Integer studentId){
//        System.out.println(studentId);
        studentService.deleteStudent(studentId);
        return "redirect:/student";
    }
}
